home *** CD-ROM | disk | FTP | other *** search
/ Super PC 33 / Super PC 33 (Shareware).iso / spc / sonido / timidity / source / config.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-17  |  10.3 KB  |  324 lines

  1. /*
  2.     TiMidity -- Experimental MIDI to WAVE converter
  3.     Copyright (C) 1995 Tuukka Toivonen <titoivon@snakemail.hut.fi>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* Win32 patches by Davide Moretti. */
  21.  
  22. /* Filename extension, followed by command to run decompressor so that
  23.     output is written to stdout. Terminate the list with a 0.
  24.  
  25.     Any file with a name ending in one of these strings will be run
  26.     through the corresponding decompressor. If you don't like this
  27.     behavior, you can undefine DECOMPRESSOR_LIST to disable automatic
  28.     decompression entirely. */
  29. #ifndef __WIN32__
  30. #define DECOMPRESSOR_LIST { \
  31.                     ".gz", "gunzip -c %s", \
  32.                     ".Z", "zcat %s", \
  33.                     ".zip", "unzip -p %s", \
  34.                     ".lha", "lha -pq %s", \
  35.                     ".lzh", "lha -pq %s", \
  36.                     ".shn", "shorten -x %s -", \
  37.                     ".wav", "wav2pat %s", \
  38.                   0 }
  39. #endif
  40.  
  41. /* When a patch file can't be opened, one of these extensions is
  42.     appended to the filename and the open is tried again. */
  43. #ifdef __WIN32__
  44. #define PATCH_EXT_LIST { ".pat", 0 }
  45. #else
  46. #define PATCH_EXT_LIST { \
  47.                 ".pat", \
  48.                 ".shn", ".pat.shn", \
  49.                 ".gz", ".pat.gz", \
  50.                 0 }
  51. #endif
  52.  
  53. /* Acoustic Grand Piano seems to be the usual default instrument. */
  54. #define DEFAULT_PROGRAM 0
  55.  
  56. /* 9 here is MIDI channel 10, which is the standard percussion channel.
  57.     Some files (notably C:\WINDOWS\CANYON.MID) think that 16 is one too.
  58.     On the other hand, some files know that 16 is not a drum channel and
  59.     try to play music on it. This is now a runtime option, so this isn't
  60.     a critical choice anymore. */
  61. /* #define DEFAULT_DRUMCHANNELS ((1<<9) | (1<<15)) */
  62. #define DEFAULT_DRUMCHANNELS (1<<9)
  63.  
  64. /* A somewhat arbitrary frequency range. The low end of this will
  65.     sound terrible as no lowpass filtering is performed on most
  66.     instruments before resampling. */
  67. #define MIN_OUTPUT_RATE     4000
  68. #define MAX_OUTPUT_RATE     65000
  69.  
  70. /* In percent. */
  71. #define DEFAULT_AMPLIFICATION     100
  72.  
  73. /* Default sampling rate, default polyphony, and maximum polyphony.
  74.     All but the last can be overridden from the command line. */
  75. #define DEFAULT_RATE    32000
  76. #define DEFAULT_VOICES    32
  77. #define MAX_VOICES    48
  78.  
  79. /* The size of the internal buffer is 2^AUDIO_BUFFER_BITS samples.
  80.     This determines maximum number of samples ever computed in a row.
  81.  
  82.     For Linux and FreeBSD u8sers:
  83.  
  84.     This also specifies the size of the buffer fragment.  A smaller
  85.     fragment gives a faster response in interactive mode -- 10 or 11 is
  86.     probably a good number. Unfortunately some sound cards emit a click
  87.     when switching DMA buffers. If this happens to you, try increasing
  88.     this number to reduce the frequency of the clicks.
  89.  
  90.     For other systems:
  91.  
  92.     You should probably use a larger number for improved performance.
  93.  
  94. */
  95. #ifdef __WIN32__
  96. #define AUDIO_BUFFER_BITS 12
  97. #else
  98. #define AUDIO_BUFFER_BITS 11
  99. #endif
  100.  
  101. /* 1000 here will give a control ratio of 22:1 with 22 kHz output.
  102.     Higher CONTROLS_PER_SECOND values allow more accurate rendering
  103.     of envelopes and tremolo. The cost is CPU time. */
  104. #define CONTROLS_PER_SECOND 1000
  105.  
  106. /* Strongly recommended. This option increases CPU usage by half, but
  107.     without it sound quality is very poor. */
  108. #define LINEAR_INTERPOLATION
  109.  
  110. /* This is an experimental kludge that needs to be done right, but if
  111.     you've got an 8-bit sound card, or cheap multimedia speakers hooked
  112.     to your 16-bit output device, you should definitely give it a try.
  113.  
  114.     Defining LOOKUP_HACK causes table lookups to be used in mixing
  115.     instead of multiplication. We convert the sample data to 8 bits at
  116.     load time and volumes to logarithmic 7-bit values before looking up
  117.     the product, which degrades sound quality noticeably.
  118.  
  119.     Defining LOOKUP_HACK should save ~20% of CPU on an Intel machine.
  120.     LOOKUP_INTERPOLATION might give another ~5% */
  121. /* #define LOOKUP_HACK
  122.     #define LOOKUP_INTERPOLATION */
  123.  
  124. /* Make envelopes twice as fast. Saves ~20% CPU time (notes decay
  125.     faster) and sounds more like a GUS. There is now a command line
  126.     option to toggle this as well. */
  127. #define FAST_DECAY
  128.  
  129. /* How many bits to use for the fractional part of sample positions.
  130.     This affects tonal accuracy. The entire position counter must fit
  131.     in 32 bits, so with FRACTION_BITS equal to 12, the maximum size of
  132.     a sample is 1048576 samples (2 megabytes in memory). The GUS gets
  133.     by with just 9 bits and a little help from its friends...
  134.     "The GUS does not SUCK!!!" -- a happy user :) */
  135. #define FRACTION_BITS 12
  136.  
  137. /* For some reason the sample volume is always set to maximum in all
  138.     patch files. Define this for a crude adjustment that may help
  139.     equalize instrument volumes. */
  140. #define ADJUST_SAMPLE_VOLUMES
  141.  
  142. /* If you have root access, you can define DANGEROUS_RENICE and chmod
  143.     timidity setuid root to have it automatically raise its priority
  144.     when run -- this may make it possible to play MIDI files in the
  145.     background while running other CPU-intensive jobs. Of course no
  146.     amount of renicing will help if the CPU time simply isn't there.
  147.  
  148.     The root privileges are used and dropped at the beginning of main()
  149.     in timidity.c -- please check the code to your satisfaction before
  150.     using this option. (And please check sections 11 and 12 in the
  151.     GNU General Public License (under GNU Emacs, hit ^H^W) ;) */
  152. /* #define DANGEROUS_RENICE -15 */
  153.  
  154. /* The number of samples to use for ramping out a dying note. Affects
  155.     click removal. */
  156. #define MAX_DIE_TIME 20
  157.  
  158. /* On some machines (especially PCs without math coprocessors),
  159.     looking up sine values in a table will be significantly faster than
  160.     computing them on the fly. Uncomment this to use lookups. */
  161. /* #define LOOKUP_SINE */
  162.  
  163. /* Shawn McHorse's resampling optimizations. These may not in fact be
  164.     faster on your particular machine and compiler. You'll have to run
  165.     a benchmark to find out. */
  166. #define PRECALC_LOOPS
  167.  
  168. /* If calling ldexp() is faster than a floating point multiplication
  169.     on your machine/compiler/libm, uncomment this. It doesn't make much
  170.     difference either way, but hey -- it was on the TODO list, so it
  171.     got done. */
  172. /* #define USE_LDEXP */
  173.  
  174. /**************************************************************************/
  175. /* Anything below this shouldn't need to be changed unless you're porting
  176.     to a new machine with other than 32-bit, big-endian words. */
  177. /**************************************************************************/
  178.  
  179. /* change FRACTION_BITS above, not these */
  180. #define INTEGER_BITS (32 - FRACTION_BITS)
  181. #define INTEGER_MASK (0xFFFFFFFF << FRACTION_BITS)
  182. #define FRACTION_MASK (~ INTEGER_MASK)
  183.  
  184. /* This is enforced by some computations that must fit in an int */
  185. #define MAX_CONTROL_RATIO 255
  186.  
  187. /* Audio buffer size has to be a power of two to allow DMA buffer
  188.     fragments under the VoxWare (Linux & FreeBSD) audio driver */
  189. #define AUDIO_BUFFER_SIZE (1<<AUDIO_BUFFER_BITS)
  190.  
  191. /* Byte order, defined in <machine/endian.h> for FreeBSD */
  192. #ifdef linux
  193. /*
  194.  * Byte order is defined in <bytesex.h> as __BYTE_ORDER, that need to
  195.  * be checked against __LITTLE_ENDIAN and __BIG_ENDIAN defined in <endian.h>
  196.  * <endian.h> includes automagically <bytesex.h>
  197.  * for Linux.
  198.  */
  199. #include <endian.h>
  200.  
  201. /*
  202.  * We undef the two things to start with a clean situation
  203.  * (oddly enough, <endian.h> defines under certain conditions
  204.  * the two things below, as __LITTLE_ENDIAN and __BIG_ENDIAN, that
  205.  * are useless for our plans)
  206.  */
  207. #undef LITTLE_ENDIAN
  208. #undef BIG_ENDIAN
  209.  
  210. # if __BYTE_ORDER == __LITTLE_ENDIAN
  211. #  define LITTLE_ENDIAN
  212. # elif __BYTE_ORDER == __BIG_ENDIAN
  213. #  define BIG_ENDIAN
  214. # else
  215. # error No byte sex defined
  216. # endif
  217. #endif
  218.  
  219. /* Win32 on Intel machines */
  220. #ifdef __WIN32__
  221. #define LITTLE_ENDIAN
  222. #endif
  223.  
  224. typedef unsigned long uint32;
  225. typedef long int32;
  226. typedef unsigned short uint16;
  227. typedef short int16;
  228. typedef unsigned char uint8;
  229. typedef char int8;
  230.  
  231. /* Instrument files are little-endian, MIDI files big-endian, so we
  232.     need to do some conversions. */
  233.  
  234. #define XCHG_SHORT(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
  235. #ifdef __i486__
  236. # define XCHG_LONG(x) \
  237.       ({ int32 __value; \
  238.           asm ("bswap %1; movl %1,%0" : "=g" (__value) : "r" (x)); \
  239.          __value; })
  240. #else
  241. # define XCHG_LONG(x) ((((x)&0xFF)<<24) | \
  242.                 (((x)&0xFF00)<<8) | \
  243.                 (((x)&0xFF0000)>>8) | \
  244.                 (((x)>>24)&0xFF))
  245. #endif
  246.  
  247. #ifdef LITTLE_ENDIAN
  248. #define LE_SHORT(x) x
  249. #define LE_LONG(x) x
  250. #define BE_SHORT(x) XCHG_SHORT(x)
  251. #define BE_LONG(x) XCHG_LONG(x)
  252. #else
  253. #define BE_SHORT(x) x
  254. #define BE_LONG(x) x
  255. #define LE_SHORT(x) XCHG_SHORT(x)
  256. #define LE_LONG(x) XCHG_LONG(x)
  257. #endif
  258.  
  259. #define MAX_AMPLIFICATION 800
  260.  
  261. /* You could specify a complete path, e.g. "/etc/timidity.cfg", and
  262.     then specify the library directory in the configuration file. */
  263. #define CONFIG_FILE    "timidity.cfg"
  264.  
  265. /* These affect general volume */
  266. #define GUARD_BITS 3
  267. #define AMP_BITS (15-GUARD_BITS)
  268.  
  269. #ifdef LOOKUP_HACK
  270.     typedef int8 sample_t;
  271.     typedef uint8 final_volume_t;
  272. #  define FINAL_VOLUME(v) (~_l2u[v])
  273. #  define MIXUP_SHIFT 5
  274. #  define MAX_AMP_VALUE 4095
  275. #else
  276.     typedef int16 sample_t;
  277.     typedef int32 final_volume_t;
  278. #  define FINAL_VOLUME(v) (v)
  279. #  define MAX_AMP_VALUE ((1<<(AMP_BITS+1))-1)
  280. #endif
  281.  
  282. #ifdef USE_LDEXP
  283. #  define FSCALE(a,b) ldexp((a),(b))
  284. #  define FSCALENEG(a,b) ldexp((a),-(b))
  285. #else
  286. #  define FSCALE(a,b) ((a) * (double)(1<<(b)))
  287. #  define FSCALENEG(a,b) ((a) * (1.0L / (double)(1<<(b))))
  288. #endif
  289.  
  290. /* Vibrato and tremolo Choices of the Day */
  291. #define SWEEP_TUNING 38
  292. #define VIBRATO_AMPLITUDE_TUNING 1.0L
  293. #define VIBRATO_RATE_TUNING 38
  294. #define TREMOLO_AMPLITUDE_TUNING 1.0L
  295. #define TREMOLO_RATE_TUNING 38
  296.  
  297. #define SWEEP_SHIFT 16
  298. #define RATE_SHIFT 5
  299.  
  300. #define VIBRATO_SAMPLE_INCREMENTS 32
  301.  
  302. #ifdef HPUX
  303.   extern char *sys_errlist[];
  304. #endif
  305.  
  306. #ifdef SUN
  307. #include <sys/stdtypes.h>
  308. #include <errno.h>
  309.   extern char *sys_errlist[];
  310.   extern int opterr;
  311.   extern int optind;
  312.   extern int optopt;
  313.   extern char *optarg;
  314. #endif
  315.  
  316. /* The path separator (D.M.) */
  317. #ifdef __WIN32__
  318. #define PATH_SEP '\\'
  319. #define PATH_STRING "\\"
  320. #else
  321. #define PATH_SEP '/'
  322. #define PATH_STRING "/"
  323. #endif
  324.